﻿using System;
using System.Collections.Generic;
using System.Web.Script.Services;
using System.Web.Services;
using AjaxControlToolkit;

namespace ControlToolkitExtended.WebExample
{
    /// <summary>
    /// Summary description for HierarchicData
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class HierarchicData : System.Web.Services.WebService
    {

        [WebMethod]
        [ScriptMethod]
        public string[] GetChildren(string contextKey)
        {
            List<string> result = null;
            result = Context.Cache["GetChildren"+contextKey] as List<string>;
            if (result == null)
            {
                result = new List<string>();
                Random r = new Random();
                int childCount = r.Next(0, 20);
                for (int i = 0; i < childCount; i++)
                {
                    result.Add( AutoCompleteExtender.CreateAutoCompleteItem( "child for "+contextKey+" "+i,  Guid.NewGuid().ToString("N")));
                }
                Context.Cache["GetChildren" + contextKey] = result;
            }
            return result.ToArray();
        }
    }
}
